//
//  ViewController.m
//  MCModify
//
//  Created by 陆绍波 on 2018/11/15.
//  Copyright © 2018 陆绍波. All rights reserved.
//

#import "ViewController.h"
#import <Masonry.h>
#import "MCUserModel.h"
#import "MCUserInfoCell.h"
#import "MCHeaderView.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong) UITableView *tableView;
@property(nonatomic,strong) NSArray <MCUserModel *> *dataSource;
@end

static NSString *const kCellID = @"MCUserInfoCell";
@implementation ViewController
- (NSArray *)dataSource{
    if (nil == _dataSource) {
        NSString *path = [[NSBundle mainBundle]pathForResource:@"userInfoMenu.plist" ofType:nil];
        NSArray *array = [NSArray arrayWithContentsOfFile:path];
         NSMutableArray *tempDict = [[NSMutableArray alloc]init];
        for (NSDictionary *dict in array) {
            MCUserModel *model = [[MCUserModel alloc]initWithDict:dict];
             [tempDict addObject:model];
        }
        _dataSource = tempDict.copy;
    }
    return _dataSource;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTableView];
    
}
- (void)setupTableView{
    _tableView = [[UITableView alloc]init];
    _tableView.delegate = self;
    _tableView.dataSource = self;
     [self.view addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
    [_tableView registerNib:[UINib nibWithNibName:kCellID bundle:nil] forCellReuseIdentifier:kCellID];
    UIView *headerView = [[[NSBundle mainBundle]loadNibNamed:@"MCHeaderView" owner:nil options:nil]lastObject];
    [_tableView setTableHeaderView: headerView];
    [_tableView reloadData];
}

#pragma mark - tableView数据源
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MCUserInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
    MCUserModel *modle = self.dataSource[indexPath.row];
    cell.model = modle;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}
@end
